<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>修改密码</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../css/layui.css" media="all">
		<!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
	</head>

	<body>

		<div id="app">
			<div class="layui-container">
				<div class="layui-row ">
					<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
						<legend>修改密码</legend>
					</fieldset>

					<div class="layui-col-md-offset3" style="margin-top: 100px;">
						<form class="layui-form" action="">

							<div class="layui-form-item">
								<label class="layui-form-label"><i class="layui-icon layui-icon-password" ></i></label>
								<div class="layui-input-inline">
									<input type="password"id="oldpwd" name="stuPwd" v-model="oldPwd" lay-verify="pass" placeholder="请输入原密码" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid layui-word-aux"></div>
							</div>

							<div class="layui-form-item">
								<label class="layui-form-label"><i class="layui-icon layui-icon-password" ></i></label>
								<div class="layui-input-inline">
									<input type="password" id="npwd" name="stuPwd" lay-verify="pass" placeholder="请输入新密码" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid layui-word-aux"></div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label"><i class="layui-icon layui-icon-password" ></i></label>
								<div class="layui-input-inline">
									<input type="password" id="npwdt" name="stuPwd" v-model="newPwd" lay-verify="pass" placeholder="请再次输入新密码" autocomplete="off" class="layui-input">
								</div>
								<div class="layui-form-mid layui-word-aux"></div>
							</div>

							<div class="layui-form-item" style="margin-top: 25px;">
								<div class="layui-input-block">
									<!--lay-submit="" lay-filter="demo1"-->
									<button type="button" class="layui-btn" @click="stuUpdatePwd()">确认更改</button>
									<button type="reset" class="layui-btn layui-btn-primary">重置</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>

			<div class="layui-container">
				<div class="layui-fluid">

				</div>
			</div>
		</div>
		<script src="../layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../js/jquery.min.js"></script>
		<script type="text/javascript" src="../js/vue.min.js"></script>
		<script type="text/javascript" src="../js/jquery.cookie.js"></script>
		<script src="http://cdn.bootcss.com/blueimp-md5/1.1.0/js/md5.min.js"></script>
		<script>
			
			$(function() {
				$(document).bind("contextmenu",function(e){   
         			 return false;   
    			});
				
				$.ajax({
					url:"http://localhost:8080/student/nodo.do",
					async:"get",
					dataType:"json",
					data:{
						sid:$.cookie("sid")
					},
					success:function(data){
						if(data.info == "404"){
							window.location.href="stulogin.html";
						}
					}
					
				})
				
				
				
				var vue = new Vue({
					"el": "#app",
					"data": {
						oldPwd: "",
						newPwd: ""
					},
					"methods": {
						"stuUpdatePwd": function() {
							//alert("@@成功" + this.oldPwd + ":" + this.newPwd);
							
							
							var npwd=$("#npwd").val();
							var npwdt=$("#npwdt").val();
							if(npwd==npwdt){
								
							var npwdhash = md5(npwd);
							var oldpedhash = md5(this.oldPwd);
							
							
							
							
							
							var newPwd = npwdhash;
							var oldPwd = oldpedhash;
							
							$.ajax({
								type: "post",
								url: "http://localhost:8080/student/updatePwd.do",
								async: false,
								dataType: "json",
								data: {
									//message: JSON.stringify(data.field)
									oldPwd: oldPwd,
									newPwd: newPwd,
									sid: $.cookie("sid")
								},
								success: function(data) {
									console.log(data);
									//alert("数据：" + data);
									if(data.info == '404') {
										window.location.href = "../student/stulogin.html";
									} else {
										if(data == "pwdOk") {
											alert("修改成功");
											window.location.href = "notify.html";
										} else if(data == "pwdNo") {
											alert("原密码错误");
											window.location.href = "changepwd.html";
										}
									}

								},
								error: function(data) {
									alert("失败");
								}
							});
							
							}else{
								alert("两次输入密码不一致");
							}
							
							
							
							
						}
					}

				})
			})

			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;

				//日期
				laydate.render({
					elem: '#date'
				});
				laydate.render({
					elem: '#date1'
				});

				//创建一个编辑器
				var editIndex = layedit.build('LAY_demo_editor');

				//自定义验证规则
				form.verify({
					title: function(value) {
						if(value.length != 12) {
							return '学号不正确';
						}
					},
					pass: [/(.+){6,20}$/, '密码必须6到20位'],
					content: function(value) {
						layedit.sync(editIndex);
					}
				});

				//监听指定开关
				form.on('switch(switchTest)', function(data) {
					layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
						offset: '6px'
					});
					layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
				});

				

			});
		</script>

	</body>

</html>